package fp.poczadly.client.event;

import com.google.gwt.event.shared.GwtEvent;

import fp.poczadly.shared.User;
import fp.poczadly.shared.Utils;

public class LoginEvent extends GwtEvent<LoginEventHandler> {
	public static Type<LoginEventHandler> TYPE = new Type<LoginEventHandler>();

	private User user = null;

	public LoginEvent( User user ) {
		this.user = user;
	}

	@Override
	public Type<LoginEventHandler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch( LoginEventHandler handler ) {
		handler.addUser( this );
	}

	public User getLoggedUser() throws NullPointerException {
		if( user == null )
			throw new NullPointerException( Utils.USER_IS_ALREADY_LOGED );
		
		return user;
	}

}
